﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using Model;
using System.Configuration;
namespace NCRE学生考试端V1._0
{
    public partial class frmShowOnLineStd : Form
    {
        public frmShowOnLineStd()
        {
            InitializeComponent();
        }
        //定义一个StudentBindPaperTypeBLL类
        StudentBindPaperTypeBLL studentBindPaperType = new StudentBindPaperTypeBLL();
        //定义一个StudentBindPaperTypeEntity类
        StudentBindPaperTypeEntity studentBindPaperTypeEntity = new StudentBindPaperTypeEntity();
        Dictionary<string, string> dicPlace = new Dictionary<string, string>();
        private void frmShowOnLineStd_Load(object sender, EventArgs e)
        {
           
            cboPlace.DataSource = getPalceByIp().Keys.ToList();           
            DataTable dt = new DataTable();
            StudentInfoEntity studentInfoEntity = new StudentInfoEntity();
          
            String ip = "";
            if (cboPlace.Text != "")
            {
                ip = dicPlace[cboPlace.Text];
            }
            else
            {
                MessageBox.Show("请输入ip");
                return;
            }
            //string strPlace = getPalceByIp()[cboPlace.Text];
            
            studentBindPaperTypeEntity.TimeTamp = MyInfo.shijian() + " " + MyInfo.time();
            dt = studentBindPaperType.OnLineStudentbyPlace(studentBindPaperTypeEntity, ip);
            if (dt.Rows.Count == 0)
            {
                dgvStudent.DataSource = null;
            }
            else
            {
                dgvStudent.DataSource = null;
                dgvStudent.DataSource = dt;
            }
        }
        private void cboPlace_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            studentBindPaperTypeEntity.TimeTamp = MyInfo.shijian() + " " + MyInfo.time();
            String ip = "";
            if (cboPlace.Text != "")
            {
                ip = dicPlace[cboPlace.Text];
            }
            else
            {
                MessageBox.Show("请输入ip");
                return;
            }
  
            dt = studentBindPaperType.OnLineStudentbyPlace(studentBindPaperTypeEntity, ip);
            if (dt.Rows.Count == 0)
            {
                dgvStudent.DataSource = null;
            }
            else
            {
                dgvStudent.DataSource = null;
                dgvStudent.DataSource = dt;
            }
        }
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (cboPlace.Items.Count == 0)
            {
                MessageBox.Show("该考场无学生", "提示", MessageBoxButtons.OK,
                MessageBoxIcon.Warning);
            }
            else
            {
                ExcelExport excelexcport = new ExcelExport();
                excelexcport.setExcelStd(dgvStudent, cboPlace.GetItemText(cboPlace.Text));
            }
        }

        #region 获取对应IPC段的对应的考场名称
        /// <summary>
        /// 获取对应IPC段的对应的考场名称
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, string> getPalceByIp()
        {          
            string[] keys = ConfigurationManager.AppSettings.AllKeys;
            for (int i = 0; i < keys.Length; i++)
            {
                string key = keys[i];
                //通过Key来索引Value
                string value = ConfigurationManager.AppSettings[key];               
                dicPlace.Add(key, value);
            }                  
            return dicPlace;
        }
        #endregion




    }
}
